﻿Chenxin.UI.PPCMgr=Chenxin.extend(Chenxin.UI.PageCommon,{
	actionUrl:'/service/ProtectedPhoneConfigMgr.ashx',
	createGrid:function(){			
		return new Chenxin.UI.ExpandGrid({
			actionUrl:this.actionUrl+'?op=getlist',
			id:'ppcmgr_grid',
			renderTo:'ppcm_table',
			columns:{
				ConfigType:{
					head:'配置类型',
					width:100,
					sortable:true
				},
				ConfigMinValue:{
					head:'最小值',
					width:60,
					sortable:true
				},
				ConfigMaxValue:{
					head:'最大值',
					width:60,
					sortable:true
				},
				ConfigValue:{
					head:'文本值',
					sortable:true
				},
				ConfigControlType:{
					head:'控制类型',
					width:80,
					sortable:true
				},
				City:{
					head:'城市',
					width:80,
					sortable:true
				},
				Company:{
					head:'公司',
					width:80,
					sortable:true
				}
			},
			scope:this
		});
	},
	initEvent:function(){
		var _this=this;
		$('#btn_add').click(function(){
            _this.add();
			_this.form.op='add';   
			_this.form.reset();
		});	
		$('#btn_del').click(function(){
            _this.delList();
        });
		
		$('#btn_edit').click(function(){
            _this.edit();
        });
	},
	createForm:function(){
		return new Chenxin.UI.PPCMgrForm({
			scope:this,
			beforeFitData:function(model){
				if(this.form.op=='edit'){				
					this.form.showValueTr(model.ConfigControlType,model.ConfigType,model.ConfigMinValue);
					var company=this.form.findByName('CompanyId');
					company.param.fatherid=model.CityId;
					company.reload(model.CompanyId);
				}
			},
			afterGetFormJson:function(model){
				if(model.ConfigControlType==20){
					model.ConfigMinValue=model.Sel;
					model.ConfigMaxValue=model.Sel;
					
				}
				if(model.Sel){
					delete model.Sel;
				}
			},
			saveSucc:function(data,msg){
				this.grid.reload();	
			}
		});
	},
	createSearch:function(){
		return new Chenxin.UI.PPCMgrSearch({
			scope:this
		});
	},
	initComponent:function(){
		Chenxin.UI.PPCMgr.superclass.initComponent.call(this);
	}
});

Chenxin.UI.PPCMgrForm=Chenxin.extend(Chenxin.UI.FormCommon,{
	actionUrl:'service/ProtectedPhoneConfigMgr.ashx',
	id:'ppcmWin',
	jqmWidth:500,
	renderTo:'jqm_ppc',
	title:'新增配置',
	createForm:function(){
		return Chenxin.FormCommon.ppcMgrForm(this.id);
	},
	
	createComboList:function(){
		var _this=this;		
				
		//城市
		var city=new Chenxin.UI.StructCombo({
			param:{op:'getcity'},
			containerId:'#'+this.id+'_City',
			name:'CityId',
			inModelType:'all',
			txtModelName:'City',
			required:true,
			tbxWidth:60,
			onSelected:function(){
				if(this.getValue()==this.defVal){
					company.clearItems();
				}else{
					company.param.fatherid=this.getValue();
					company.reload();				
				}				
			}
		});
		
		//公司
		var company=new Chenxin.UI.StructCombo({
			autoLoad:false,
			tbxWidth:60,
			param:{op:'getcompany'},
			name:'CompanyId',
			containerId:'#'+this.id+'_Company',
			inModelType:'all',
			required:true,
			txtModelName:'Company'
		});
		
		//配置类型
		var configType=new Chenxin.UI.Combo({
			name:'ConfigType',
			required:true,
			tbxWidth:60,
			containerId:'#'+this.id+'_ConfigType',
			items:comboCommon.PhoneConfigType
		});
		
		//输入控制类型
		var controlType=new Chenxin.UI.Combo({
			name:'ConfigControlType',
			required:true,
			tbxWidth:60,
			containerId:'#'+this.id+'_ConfigControlType',
			items:comboCommon.PhoneConfigControlType,
			onSelected:function(){
				_this.showValueTr(this.getValue(),configType.getValue());
			}
		});
		
		
		//下拉选择
		var sel=new Chenxin.UI.ParameterCombo({
			name:'Sel',
			autoLoad:false,
			tbxWidth:60,
			containerId:'#'+this.id+'_SelectValue',
			items:[]
		});
		
		return [city,company,configType,controlType,sel];
	},
	showValueTr:function(controlVal,key,val){
		switch(controlVal){
			case 10:
				$('.tr_sel').hide();
				$('.tr_num').show();
				$('.tr_txt').hide();
				break;
			case 20:
				$('.tr_sel').show();
				$('.tr_num').hide();
				$('.tr_txt').hide();
				var sel=this.findByName('Sel');
				sel.key=key;
				sel.reload(val);
				break;
			case 30:
				$('.tr_sel').hide();
				$('.tr_num').hide();
				$('.tr_txt').show();
				break;
			default:
				$('.tr_sel').hide();
				$('.tr_num').hide();
				$('.tr_txt').hide();
				break;
		}
	},
	initEvent:function(){
				
		var _this=this;
		$('#'+this.id+'_Save').live('click',function(){
			_this.save();
		});
		$('#'+this.id+'_Cancle').live('click',function(){
			_this.hide();
		});	
	},
	reset:function(){
		this.showValueTr();
		Chenxin.UI.PPCMgrForm.superclass.reset.call(this);
	},
	initComponent:function(){
		Chenxin.UI.PPCMgrForm.superclass.initComponent.call(this);
	}
});


/**
*查询面板
*/
Chenxin.UI.PPCMgrSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id:'ppcm_search',
	initEvent:function(){
		var _this=this;
		$('#btn_search').live('click',function(){
			_this.scope.reloadGrid();
		});
		
	},
	createComboList:function(){	
		
		//城市
		var city=new Chenxin.UI.StructCombo({
			param:{op:'getcity'},
			containerId:'#City',
			name:'cityid',
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					this.defVal=this.items[0].val;
					this.defTxt=this.items[0].txt;
					company.param.fatherid=this.defVal;
					company.reload();
				}else{
					this.addPleaseSelected=true;
					this.defVal='请选择';
					this.defTxt='请选择';				
				}
			},
			onSelected:function(){
				if(this.getValue()==this.defVal){
					company.clearItems();
				}else{					
					company.param.fatherid=this.getValue();
					company.reload();
				}
			}
		});
		
		//公司
		var company=new Chenxin.UI.StructCombo({
			autoLoad:false,
			param:{op:'getcompany'},
			name:'companyid',
			containerId:'#Company',
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					this.defVal=this.items[0].val;
					this.defTxt=this.items[0].txt;
				}else{
					this.addPleaseSelected=true;
					this.defVal='请选择';
					this.defTxt='请选择';							
				}
			}
		});
		
		
		
		//配置类型
		var configType=new Chenxin.UI.Combo({
			name:'ConfigType',
			containerId:'#ConfigType',
			items:comboCommon.PhoneConfigType
		});
		
		return [city,company,configType];
	},
	initComponent:function(){
		Chenxin.UI.PPCMgrSearch.superclass.initComponent.call(this);
	}
});


/**
*@description 楼盘DIV
*@method 提交按钮的处理方法
*/
Chenxin.FormCommon.ppcMgrForm=function(comboIdPrefix){
        return '<table class="tbl_f"><tbody><tr><th style="width:70px;"><span class="isfilled">*</span>城市：</th><td><div id="' + comboIdPrefix + '_City" style="z-index:909; margin-right: 5px;" class="SelectWrapSingle validator"></div></td><th style="width:70px;"><span class="isfilled">*</span>公司：</th><td><div id="' + comboIdPrefix + '_Company" style="z-index:908;margin-right: 5px;" class="SelectWrapSingle validator"></div></td></tr><tr><th><span class="isfilled">*</span>配置类型：</th><td><div id="' + comboIdPrefix + '_ConfigType" style="z-index:907;margin-right: 5px;" class="SelectWrapSingle validator"></div></td><th><span class="isfilled">*</span>控制类型：</th><td><div id="' + comboIdPrefix + '_ConfigControlType" style="z-index:906;margin-right: 5px;" class="SelectWrapSingle validator"></div></td></tr><tr class="tr_sel"><th><span class="isfilled">*</span>值：</th><td colspan="3"><div id="' + comboIdPrefix + '_SelectValue" style="z-index:905;margin-right: 5px;" class="SelectWrapSingle validator"></div></td></tr><tr class="tr_num"><th><span class="isfilled">*</span>最小值：</th><td><input type="text" style="width: 120px;" value="" class="inputbox_n fl" name="ConfigMinValue" /></td><th><span class="isfilled">*</span>最大值：</th><td><input type="text" style="width: 120px;" value="" class="inputbox_n fl" name="ConfigMaxValue" /></td></tr><tr class="tr_txt"><th><span class="isfilled">*</span>文本值：</th><td colspan="3"><input type="text" style="width: 120px;" value="" class="inputbox_n fl" name="ConfigValue" /></td></tr><tr><td colspan="4"><div class="tdline"></div></td></tr><tr><td colspan="4" align="right"><div style="float:right; margin-right:15px;"><input type="hidden" name="ConfigId"/><a id="' + comboIdPrefix + '_Save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + comboIdPrefix + '_Cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></tbody></table>'
}

$(document).ready(function(){
	var ppcm=new Chenxin.UI.PPCMgr();
})





















